package com.zz.component;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
    private MyReceiver myReceiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //都采用动态
        Button btnStartService = findViewById(R.id.btn_start_service);
        Button btnStopService = findViewById(R.id.btn_stop_service);
        btnStartService.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //广播/服务都是由intent类来启动的
                //显示意图：由主类发出，MyService类接收
                Intent intent = new Intent(MainActivity.this, MyService.class);//Intent（主活动.this，类)
                startService(intent);//服务的启动
            }
        });
        btnStopService.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, MyService.class);
                stopService(intent);//服务的停止
            }
        });
        //动态注册系统广播
        //IntentFilter在as6以上在意图的接收上都不大支持静态的注册方式,所以采取动态注册，action
        IntentFilter intentFilter = new IntentFilter();//创建过滤器
        intentFilter.addAction("android.intent.action.AIRPLANE_MODE");//添加一个动作在过滤器中，飞行模式
        myReceiver = new MyReceiver();
        registerReceiver(myReceiver, intentFilter);

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //销毁已注册的系统广播
        unregisterReceiver(myReceiver);
    }
    public void openCamera(View view){
        //隐示意图
        Intent intent = new Intent();
        intent.setAction("android.media.action.IMAGE_CAPTURE");
        intent.addCategory("android.intent.category.DEFAULT");
        startActivity(intent);
    }
}